home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / g_quake / shockab.zip / WEAPONS.QC < prev    next >
Text File  |  1996-10-14  |  30KB  |  1,388 lines

  1. /*
  2. */
  3. void (entity targ, entity inflictor, entity attacker, float damage) T_Damage;
  4. void (entity targ, entity attacker, float damage) S_Damage;
  5. void () player_run;
  6. void(entity bomb, entity attacker, float rad, entity ignore) T_RadiusDamage;
  7. void(vector org, vector vel, float damage) SpawnBlood;
  8. void() SuperDamageSound;
  9. void(vector org, vector vel) create_bubble;
  10.  
  11. // The FLYING_AWAY (tm) Animation Phases
  12.  
  13. void() army_fly1;
  14. void() demon1_fly1;
  15. void() dog_fly1;
  16. void() enf_fly1;
  17. void() f_pain1;
  18. void() hknight_fly1;
  19. void() knight_fly1;
  20. void() ogre_paind1;
  21. void() player_fly1;
  22. void() shal_fly1;
  23. void() sham_pain1;
  24. void() tbaby_fly1;
  25. void() wiz_fly1;
  26. void() zombie_paine1;
  27.  
  28. // called by worldspawn
  29. void() W_Precache =
  30. {
  31.     precache_sound ("shambler/smack.wav");    // for hitting walls
  32.     precache_sound ("fish/death.wav");        // underwater explosion
  33.     precache_sound ("weapons/r_exp3.wav");    // new rocket explosion
  34.     precache_sound ("weapons/rocket1i.wav");  // spike gun
  35.     precache_sound ("weapons/sgun1.wav");
  36.     precache_sound ("weapons/guncock.wav");   // player shotgun
  37.     precache_sound ("weapons/ric1.wav");      // ricochet (used in c code)
  38.     precache_sound ("weapons/ric2.wav");      // ricochet (used in c code)
  39.     precache_sound ("weapons/ric3.wav");      // ricochet (used in c code)
  40.     precache_sound ("weapons/spike2.wav");    // super spikes
  41.     precache_sound ("weapons/tink1.wav");     // spikes tink (used in c code)
  42.     precache_sound ("weapons/grenade.wav");   // grenade launcher
  43.     precache_sound ("weapons/bounce.wav");          // grenade bounce
  44.     precache_sound ("weapons/shotgn2.wav");   // super shotgun
  45. };
  46.  
  47. float() crandom =
  48. {
  49.     return 2*(random() - 0.5);
  50. };
  51.  
  52. /*
  53. ================
  54. W_FireAxe
  55. ================
  56. */
  57. void() W_FireAxe =
  58. {
  59.     local vector      source;
  60.     local vector      org;
  61.  
  62.     source = self.origin + '0 0 16';
  63.     traceline (source, source + v_forward*64, FALSE, self);
  64.     if (trace_fraction == 1.0)
  65.         return;
  66.     
  67.     org = trace_endpos - v_forward*4;
  68.  
  69.     if (trace_ent.takedamage)
  70.     {
  71.         trace_ent.axhitme = 1;
  72.         SpawnBlood (org, '0 0 0', 20);
  73.         T_Damage (trace_ent, self, self, 20);
  74.     }
  75.     else
  76.     {     // hit wall
  77.         sound (self, CHAN_WEAPON, "player/axhit2.wav", 1, ATTN_NORM);
  78.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  79.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  80.         WriteCoord (MSG_BROADCAST, org_x);
  81.         WriteCoord (MSG_BROADCAST, org_y);
  82.         WriteCoord (MSG_BROADCAST, org_z);
  83.     }
  84. };
  85.  
  86.  
  87. //============================================================================
  88.  
  89.  
  90. vector() wall_velocity =
  91. {
  92.     local vector      vel;
  93.     
  94.     vel = normalize (self.velocity);
  95.     vel = normalize(vel + v_up*(random()- 0.5) + v_right*(random()- 0.5));
  96.     vel = vel + 2*trace_plane_normal;
  97.     vel = vel * 200;
  98.     
  99.     return vel;
  100. };
  101.  
  102.  
  103. /*
  104. ================
  105. SpawnMeatSpray
  106. ================
  107. */
  108. void(vector org, vector vel) SpawnMeatSpray =
  109. {
  110.     local entity missile, mpuff;
  111.     local vector      org;
  112.  
  113.     missile = spawn ();
  114.     missile.owner = self;
  115.     missile.movetype = MOVETYPE_BOUNCE;
  116.     missile.solid = SOLID_NOT;
  117.  
  118.     makevectors (self.angles);
  119.  
  120.     missile.velocity = vel;
  121.     missile.velocity_z = missile.velocity_z + 250 + 50*random();
  122.  
  123.     missile.avelocity = '3000 1000 2000';
  124.     
  125. // set missile duration
  126.     missile.nextthink = time + 1;
  127.     missile.think = SUB_Remove;
  128.  
  129.     setmodel (missile, "progs/zom_gib.mdl");
  130.     setsize (missile, '0 0 0', '0 0 0');            
  131.     setorigin (missile, org);
  132. };
  133.  
  134. /*
  135. ================
  136. SpawnBlood
  137. ================
  138. */
  139. void(vector org, vector vel, float damage) SpawnBlood =
  140. {
  141.     particle (org, vel*0.1, 73, damage*2);
  142. };
  143.  
  144. /*
  145. ================
  146. spawn_touchblood
  147. ================
  148. */
  149. void(float damage) spawn_touchblood =
  150. {
  151.     local vector      vel;
  152.  
  153.     vel = wall_velocity () * 0.2;
  154.     SpawnBlood (self.origin + vel*0.01, vel, damage);
  155. };
  156.  
  157.  
  158. /*
  159. ================
  160. SpawnChunk
  161. ================
  162. */
  163. void(vector org, vector vel) SpawnChunk =
  164. {
  165.     particle (org, vel*0.02, 0, 10);
  166. };
  167.  
  168. /*
  169. ==============================================================================
  170.  
  171. MULTI-DAMAGE
  172.  
  173. Collects multiple small damages into a single damage
  174.  
  175. ==============================================================================
  176. */
  177.  
  178. entity      multi_ent;
  179. float multi_damage;
  180.  
  181. void() ClearMultiDamage =
  182. {
  183.     multi_ent = world;
  184.     multi_damage = 0;
  185. };
  186.  
  187. void() ApplyMultiDamage =
  188. {
  189.     if (!multi_ent)
  190.         return;
  191.     T_Damage (multi_ent, self, self, multi_damage);
  192. };
  193.  
  194. void(entity hit, float damage) AddMultiDamage =
  195. {
  196.     if (!hit)
  197.         return;
  198.     
  199.     if (hit != multi_ent)
  200.     {
  201.         ApplyMultiDamage ();
  202.         multi_damage = damage;
  203.         multi_ent = hit;
  204.     }
  205.     else
  206.         multi_damage = multi_damage + damage;
  207. };
  208.  
  209. /*
  210. ==============================================================================
  211.  
  212. BULLETS
  213.  
  214. ==============================================================================
  215. */
  216.  
  217. /*
  218. ================
  219. TraceAttack
  220. ================
  221. */
  222. void(float damage, vector dir) TraceAttack =
  223. {
  224.     local vector      vel, org;
  225.     
  226.     vel = normalize(dir + v_up*crandom() + v_right*crandom());
  227.     vel = vel + 2*trace_plane_normal;
  228.     vel = vel * 200;
  229.  
  230.     org = trace_endpos - dir*4;
  231.  
  232.     if (trace_ent.takedamage)
  233.     {
  234.         SpawnBlood (org, vel*0.2, damage);
  235.         AddMultiDamage (trace_ent, damage);
  236.     }
  237.     else
  238.     {
  239.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  240.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  241.         WriteCoord (MSG_BROADCAST, org_x);
  242.         WriteCoord (MSG_BROADCAST, org_y);
  243.         WriteCoord (MSG_BROADCAST, org_z);
  244.     }
  245. };
  246.  
  247. /*
  248. ================
  249. FireBullets
  250.  
  251. Used by shotgun, super shotgun, and enemy soldier firing
  252. Go to the trouble of combining multiple pellets into a single damage call.
  253. ================
  254. */
  255. void(float shotcount, vector dir, vector spread) FireBullets =
  256. {
  257.     local vector direction;
  258.     local vector      src;
  259.     
  260.     makevectors(self.v_angle);
  261.  
  262.     src = self.origin + v_forward*10;
  263.     src_z = self.absmin_z + self.size_z * 0.7;
  264.  
  265.     ClearMultiDamage ();
  266.     while (shotcount > 0)
  267.     {
  268.         direction = dir + crandom()*spread_x*v_right + crandom()*spread_y*v_up;
  269.  
  270.         traceline (src, src + direction*2048, FALSE, self);
  271.         if (trace_fraction != 1.0)
  272.             TraceAttack (4, direction);
  273.  
  274.         shotcount = shotcount - 1;
  275.     }
  276.     ApplyMultiDamage ();
  277. };
  278.  
  279. /*
  280. ================
  281. W_FireShotgun
  282. ================
  283. */
  284. void() W_FireShotgun =
  285. {
  286.     local vector dir;
  287.  
  288.     sound (self, CHAN_WEAPON, "weapons/guncock.wav", 1, ATTN_NORM);   
  289.  
  290.     self.punchangle_x = -2;
  291.     
  292.     self.currentammo = self.ammo_shells = self.ammo_shells - 1;
  293.     dir = aim (self, 100000);
  294.     FireBullets (6, dir, '0.04 0.04 0');
  295. };
  296.  
  297.  
  298. /*
  299. ================
  300. W_FireSuperShotgun
  301. ================
  302. */
  303. void() W_FireSuperShotgun =
  304. {
  305.     local vector dir;
  306.  
  307.     if (self.currentammo == 1)
  308.     {
  309.         W_FireShotgun ();
  310.         return;
  311.     }
  312.         
  313.     sound (self ,CHAN_WEAPON, "weapons/shotgn2.wav", 1, ATTN_NORM);   
  314.  
  315.     self.punchangle_x = -4;
  316.     
  317.     self.currentammo = self.ammo_shells = self.ammo_shells - 2;
  318.     dir = aim (self, 100000);
  319.     FireBullets (14, dir, '0.14 0.08 0');
  320. };
  321.  
  322.  
  323. /*
  324. ==============================================================================
  325.  
  326. ROCKETS
  327.  
  328. ==============================================================================
  329. */
  330.  
  331. void()      s_explode1  =     [0,         s_explode2] {};
  332. void()      s_explode2  =     [1,         s_explode3] {};
  333. void()      s_explode3  =     [2,         s_explode4] {};
  334. void()      s_explode4  =     [3,         s_explode5] {};
  335. void()      s_explode5  =     [4,         s_explode6] {};
  336. void()      s_explode6  =     [5,         SUB_Remove] {};
  337.  
  338. void() HitWall =
  339. {
  340.     local float dg;      
  341.  
  342.     if (other.takedamage)
  343.         return;
  344.     if (other.solid != SOLID_BSP)
  345.         return;
  346.     if (checkbottom(self))
  347.     {
  348.         self.touch = SUB_Null;
  349.         return;
  350.     }
  351.  
  352. //      bprint(ftos(self.InitialVelocity));
  353. //      bprint(" damage\n"); 
  354.     
  355.     S_Damage (self, self.owner, self.InitialVelocity * 0.1);
  356.     sound (self, CHAN_VOICE, "shambler/smack.wav", 1, ATTN_NORM);
  357.     
  358.     self.touch = SUB_Null;
  359. };
  360.  
  361. void(entity mon) FlyAway =
  362. {
  363.     if (mon.classname == "monster_army")
  364.         mon.think = army_fly1;
  365.     else if (mon.classname == "monster_demon1")
  366.         mon.think = demon1_fly1;
  367.     else if (mon.classname == "monster_dog")
  368.         mon.think = dog_fly1;
  369.     else if (mon.classname == "monster_enforcer")
  370.         mon.think = enf_fly1;
  371.     else if (mon.classname == "monster_knight")
  372.         mon.think = knight_fly1;
  373.     else if (mon.classname == "monster_zombie") 
  374.         mon.think = zombie_paine1;
  375.     else if (mon.classname == "monster_ogre")
  376.         mon.think = ogre_paind1;
  377.     else if (mon.classname == "monster_wizard")
  378.         mon.think = wiz_fly1;
  379.     else if (mon.classname == "monster_hell_knight")
  380.         mon.think = hknight_fly1;
  381.     else if (mon.classname == "monster_shalrath")
  382.         mon.think = shal_fly1;
  383.     else if (mon.classname == "monster_shambler")
  384.     {     
  385.         mon.velocity = '0 0 0';
  386.         mon.think = sham_pain1;
  387.     }
  388.     else if (mon.classname == "monster_tarbaby")
  389.         mon.think = tbaby_fly1;
  390.     else if (mon.classname == "monster_fish")
  391.         mon.think = f_pain1;
  392.     else if (mon.classname == "gibbed_head")
  393.     {      
  394.         mon.avelocity = crandom() * '600 600 600';
  395.         mon.velocity = mon.velocity * 1.5;
  396.     }
  397.     
  398.     setorigin (mon,mon.origin + '0 0 1');
  399.     mon.enemy = self.owner;
  400.     mon.InitialVelocity = vlen(mon.velocity) - 384;
  401.     if (mon.InitialVelocity > 0)
  402.         mon.touch = HitWall;
  403.     else
  404.         mon.touch = SUB_Null;
  405. };
  406.  
  407. void() ShockaExplode =
  408. {
  409.     local entity      next;
  410.     local vector      dir;
  411.     local float       s,n;
  412.  
  413.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  414.     WriteByte (MSG_BROADCAST, TE_TAREXPLOSION);
  415.     WriteCoord (MSG_BROADCAST, self.origin_x);
  416.     WriteCoord (MSG_BROADCAST, self.origin_y);
  417.     WriteCoord (MSG_BROADCAST, self.origin_z);
  418.  
  419.     s = pointcontents(self.origin); // Check if under water
  420.  
  421.     if (s <= CONTENT_WATER)
  422.     {
  423.         s = 0;
  424.         n = random() * 10 + 10;
  425.         while(s < n)
  426.         {
  427.             dir_x = crandom() * 75;
  428.             dir_y = crandom() * 75;
  429.             dir_z = random() * 75 + 5;
  430.             create_bubble(self.origin,dir);
  431.             s = s + 1;
  432.         }
  433.         sound (self, CHAN_VOICE, "fish/death.wav", 1, ATTN_NORM);
  434.     }
  435.  
  436.     next = findradius(self.origin,256);
  437.  
  438.     while(next)
  439.     {
  440.         if (next.CanBeShocked)
  441. //          if (next.movetype != MOVETYPE_NONE) // Just to make sure no doors 
  442. //          if (next.movetype != MOVETYPE_PUSH) // etc. are "shocked"
  443.         {      
  444.             dir = next.origin - self.origin;
  445.             s = 256 - vlen(dir);
  446.             dir = normalize(dir);
  447.             dir_z = 0.75;
  448.             dir = dir * s * 2;
  449.             next.velocity = dir;
  450.             dir_z = 0;
  451.             next.angles = vectoangles(dir * -1);
  452.             if (self.owner.super_damage_finished > time)
  453.                 next.velocity = next.velocity * 2;
  454.             if (next.invincible_finished >= time)
  455.                 next.velocity = '0 0 0';
  456.             if (next.flags & FL_ONGROUND)
  457.                 next.flags = next.flags - FL_ONGROUND;
  458.             FlyAway (next);
  459.         }
  460.         next = next.chain;
  461.     }
  462.     remove(self);
  463. };
  464.  
  465. void() BecomeExplosion =
  466. {
  467.     self.movetype = MOVETYPE_NONE;
  468.     self.velocity = '0 0 0';
  469.     self.touch = SUB_Null;
  470.     setmodel (self, "progs/s_explod.spr");
  471.     self.solid = SOLID_NOT;
  472.     s_explode1 ();
  473. };
  474.  
  475. void() T_MissileTouch =
  476. {
  477.     local float damg;
  478.  
  479.     if (other == self.owner)
  480.         return;           // don't explode on owner
  481.  
  482.     if (pointcontents(self.origin) == CONTENT_SKY)
  483.     {
  484.         remove(self);
  485.         return;
  486.     }
  487.  
  488.     damg = 100 + random()*20;
  489.     
  490.     if (other.health)
  491.     {
  492.         if (other.classname == "monster_shambler")
  493.             damg = damg * 0.5;      // mostly immune
  494.         T_Damage (other, self, self.owner, damg );
  495.     }
  496.  
  497.     // don't do radius damage to the other, because all the damage
  498.     // was done in the impact
  499.     T_RadiusDamage (self, self.owner, 120, other);
  500.  
  501. //    sound (self, CHAN_WEAPON, "weapons/r_exp3.wav", 1, ATTN_NORM);
  502.     self.origin = self.origin - 8*normalize(self.velocity);
  503.  
  504.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  505.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  506.     WriteCoord (MSG_BROADCAST, self.origin_x);
  507.     WriteCoord (MSG_BROADCAST, self.origin_y);
  508.     WriteCoord (MSG_BROADCAST, self.origin_z);
  509.  
  510.     BecomeExplosion ();
  511. };
  512.  
  513.  
  514.  
  515. /*
  516. ================
  517. W_FireRocket
  518. ================
  519. */
  520. void() W_FireRocket =
  521. {
  522.     local entity missile, mpuff;
  523.     
  524.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  525.     
  526.     sound (self, CHAN_WEAPON, "weapons/sgun1.wav", 1, ATTN_NORM);
  527.  
  528.     self.punchangle_x = -2;
  529.  
  530.     missile = spawn ();
  531.     missile.owner = self;
  532.     missile.movetype = MOVETYPE_FLYMISSILE;
  533.     missile.solid = SOLID_BBOX;
  534.         
  535. // set missile speed    
  536.  
  537.     makevectors (self.v_angle);
  538.     missile.velocity = aim(self, 1000);
  539.     missile.velocity = missile.velocity * 1000;
  540.     missile.angles = vectoangles(missile.velocity);
  541.     
  542.     if (self.Shocka_Gun_Active)
  543.         missile.touch = ShockaExplode;
  544.     else
  545.         missile.touch = T_MissileTouch;
  546.     
  547. // set missile duration
  548.     missile.nextthink = time + 5;
  549.     missile.think = SUB_Remove;
  550.  
  551.     setmodel (missile, "progs/missile.mdl");
  552.     setsize (missile, '0 0 0', '0 0 0');            
  553.     setorigin (missile, self.origin + v_forward*8 + '0 0 16');
  554. };
  555.  
  556. /*
  557. ===============================================================================
  558.  
  559. LIGHTNING
  560.  
  561. ===============================================================================
  562. */
  563.  
  564. /*
  565. =================
  566. LightningDamage
  567. =================
  568. */
  569. void(vector p1, vector p2, entity from, float damage) LightningDamage =
  570. {
  571.     local entity            e1, e2;
  572.     local vector            f;
  573.     
  574.     f = p2 - p1;
  575.     normalize (f);
  576.     f_x = 0 - f_y;
  577.     f_y = f_x;
  578.     f_z = 0;
  579.     f = f*16;
  580.  
  581.     e1 = e2 = world;
  582.  
  583.     traceline (p1, p2, FALSE, self);
  584.     if (trace_ent.takedamage)
  585.     {
  586.         particle (trace_endpos, '0 0 100', 225, damage*4);
  587.         T_Damage (trace_ent, from, from, damage);
  588.         if (self.classname == "player")
  589.         {
  590.             if (other.classname == "player")
  591.                 trace_ent.velocity_z = trace_ent.velocity_z + 400;
  592.         }
  593.     }
  594.     e1 = trace_ent;
  595.  
  596.     traceline (p1 + f, p2 + f, FALSE, self);
  597.     if (trace_ent != e1 && trace_ent.takedamage)
  598.     {
  599.         particle (trace_endpos, '0 0 100', 225, damage*4);
  600.         T_Damage (trace_ent, from, from, damage);
  601.     }
  602.     e2 = trace_ent;
  603.  
  604.     traceline (p1 - f, p2 - f, FALSE, self);
  605.     if (trace_ent != e1 && trace_ent != e2 && trace_ent.takedamage)
  606.     {
  607.         particle (trace_endpos, '0 0 100', 225, damage*4);
  608.         T_Damage (trace_ent, from, from, damage);
  609.     }
  610. };
  611.  
  612.  
  613. void() W_FireLightning =
  614. {
  615.     local vector            org;
  616.  
  617.     if (self.ammo_cells < 1)
  618.     {
  619.         self.weapon = W_BestWeapon ();
  620.         W_SetCurrentAmmo ();
  621.         return;
  622.     }
  623.  
  624. // explode if under water
  625.     if (self.waterlevel > 1)
  626.     {
  627.         T_RadiusDamage (self, self, 35*self.ammo_cells, world);
  628.         self.ammo_cells = 0;
  629.         W_SetCurrentAmmo ();
  630.         return;
  631.     }
  632.  
  633.     if (self.t_width < time)
  634.     {
  635.         sound (self, CHAN_WEAPON, "weapons/lhit.wav", 1, ATTN_NORM);
  636.         self.t_width = time + 0.6;
  637.     }
  638.     self.punchangle_x = -2;
  639.  
  640.     self.currentammo = self.ammo_cells = self.ammo_cells - 1;
  641.  
  642.     org = self.origin + '0 0 16';
  643.     
  644.     traceline (org, org + v_forward*600, TRUE, self);
  645.  
  646.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  647.     WriteByte (MSG_BROADCAST, TE_LIGHTNING2);
  648.     WriteEntity (MSG_BROADCAST, self);
  649.     WriteCoord (MSG_BROADCAST, org_x);
  650.     WriteCoord (MSG_BROADCAST, org_y);
  651.     WriteCoord (MSG_BROADCAST, org_z);
  652.     WriteCoord (MSG_BROADCAST, trace_endpos_x);
  653.     WriteCoord (MSG_BROADCAST, trace_endpos_y);
  654.     WriteCoord (MSG_BROADCAST, trace_endpos_z);
  655.  
  656.     LightningDamage (self.origin, trace_endpos + v_forward*4, self, 30);
  657. };
  658.  
  659.  
  660. //=============================================================================
  661.  
  662. void() GrenadeExplode =
  663. {
  664.     T_RadiusDamage (self, self.owner, 120, world);
  665.  
  666.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  667.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  668.     WriteCoord (MSG_BROADCAST, self.origin_x);
  669.     WriteCoord (MSG_BROADCAST, self.origin_y);
  670.     WriteCoord (MSG_BROADCAST, self.origin_z);
  671.  
  672.     BecomeExplosion ();
  673. };
  674.  
  675. void() GrenadeTouch =
  676. {
  677.     if (other == self.owner)
  678.         return;           // don't explode on owner
  679.     if (other.takedamage == DAMAGE_AIM)
  680.     {
  681.         if (self.owner.Shocka_Gun_Active)
  682.             ShockaExplode ();
  683.         else
  684.             GrenadeExplode ();
  685.         return;
  686.     }
  687.     sound (self, CHAN_WEAPON, "weapons/bounce.wav", 1, ATTN_NORM);    // bounce sound
  688.     if (self.velocity == '0 0 0')
  689.         self.avelocity = '0 0 0';
  690. };
  691.  
  692. /*
  693. ================
  694. W_FireGrenade
  695. ================
  696. */
  697. void() W_FireGrenade =
  698. {
  699.     local entity missile, mpuff;
  700.     
  701.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  702.     
  703.     sound (self, CHAN_WEAPON, "weapons/grenade.wav", 1, ATTN_NORM);
  704.  
  705.     self.punchangle_x = -2;
  706.  
  707.     missile = spawn ();
  708.     missile.owner = self;
  709.     missile.movetype = MOVETYPE_BOUNCE;
  710.     missile.solid = SOLID_BBOX;
  711.     missile.classname = "grenade";
  712.         
  713. // set missile speed    
  714.  
  715.     makevectors (self.v_angle);
  716.  
  717.     if (self.v_angle_x)
  718.         missile.velocity = v_forward*600 + v_up * 200 + crandom()*v_right*10 + crandom()*v_up*10;
  719.     else
  720.     {
  721.         missile.velocity = aim(self, 10000);
  722.         missile.velocity = missile.velocity * 600;
  723.         missile.velocity_z = 200;
  724.     }
  725.  
  726.     missile.avelocity = '300 300 300';
  727.  
  728.     missile.angles = vectoangles(missile.velocity);
  729.     
  730.     missile.touch = GrenadeTouch;
  731.     
  732. // set missile duration
  733.     missile.nextthink = time + 2.5;
  734.     if (self.Shocka_Gun_Active)
  735.         missile.think = ShockaExplode;
  736.     else
  737.         missile.think = GrenadeExplode;
  738.  
  739.     setmodel (missile, "progs/grenade.mdl");
  740.     setsize (missile, '0 0 0', '0 0 0');            
  741.     setorigin (missile, self.origin);
  742. };
  743.  
  744.  
  745. //=============================================================================
  746.  
  747. void() spike_touch;
  748. void() superspike_touch;
  749.  
  750.  
  751. /*
  752. ===============
  753. launch_spike
  754.  
  755. Used for both the player and the ogre
  756. ===============
  757. */
  758. void(vector org, vector dir) launch_spike =
  759. {
  760.     newmis = spawn ();
  761.     newmis.owner = self;
  762.     newmis.movetype = MOVETYPE_FLYMISSILE;
  763.     newmis.solid = SOLID_BBOX;
  764.  
  765.     newmis.angles = vectoangles(dir);
  766.     
  767.     newmis.touch = spike_touch;
  768.     newmis.classname = "spike";
  769.     newmis.think = SUB_Remove;
  770.     newmis.nextthink = time + 6;
  771.     setmodel (newmis, "progs/spike.mdl");
  772.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);       
  773.     setorigin (newmis, org);
  774.  
  775.     newmis.velocity = dir * 1000;
  776. };
  777.  
  778. void() W_FireSuperSpikes =
  779. {
  780.     local vector      dir;
  781.     local entity      old;
  782.     
  783.     sound (self, CHAN_WEAPON, "weapons/spike2.wav", 1, ATTN_NORM);
  784.     self.attack_finished = time + 0.2;
  785.     self.currentammo = self.ammo_nails = self.ammo_nails - 2;
  786.     dir = aim (self, 1000);
  787.     launch_spike (self.origin + '0 0 16', dir);
  788.     newmis.touch = superspike_touch;
  789.     setmodel (newmis, "progs/s_spike.mdl");
  790.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);       
  791.     self.punchangle_x = -2;
  792. };
  793.  
  794. void(float ox) W_FireSpikes =
  795. {
  796.     local vector      dir;
  797.     local entity      old;
  798.     
  799.     makevectors (self.v_angle);
  800.     
  801.     if (self.ammo_nails >= 2 && self.weapon == IT_SUPER_NAILGUN)
  802.     {
  803.         W_FireSuperSpikes ();
  804.         return;
  805.     }
  806.  
  807.     if (self.ammo_nails < 1)
  808.     {
  809.         self.weapon = W_BestWeapon ();
  810.         W_SetCurrentAmmo ();
  811.         return;
  812.     }
  813.  
  814.     sound (self, CHAN_WEAPON, "weapons/rocket1i.wav", 1, ATTN_NORM);
  815.     self.attack_finished = time + 0.2;
  816.     self.currentammo = self.ammo_nails = self.ammo_nails - 1;
  817.     dir = aim (self, 1000);
  818.     launch_spike (self.origin + '0 0 16' + v_right*ox, dir);
  819.  
  820.     self.punchangle_x = -2;
  821. };
  822.  
  823.  
  824.  
  825. .float hit_z;
  826. void() spike_touch =
  827. {
  828. local float rand;
  829.     if (other == self.owner)
  830.         return;
  831.  
  832.     if (other.solid == SOLID_TRIGGER)
  833.         return;     // trigger field, do nothing
  834.  
  835.     if (pointcontents(self.origin) == CONTENT_SKY)
  836.     {
  837.         remove(self);
  838.         return;
  839.     }
  840.     
  841. // hit something that bleeds
  842.     if (other.takedamage)
  843.     {
  844.         spawn_touchblood (9);
  845.         T_Damage (other, self, self.owner, 9);
  846.     }
  847.     else
  848.     {
  849.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  850.         
  851.         if (self.classname == "wizspike")
  852.             WriteByte (MSG_BROADCAST, TE_WIZSPIKE);
  853.         else if (self.classname == "knightspike")
  854.             WriteByte (MSG_BROADCAST, TE_KNIGHTSPIKE);
  855.         else
  856.             WriteByte (MSG_BROADCAST, TE_SPIKE);
  857.         WriteCoord (MSG_BROADCAST, self.origin_x);
  858.         WriteCoord (MSG_BROADCAST, self.origin_y);
  859.         WriteCoord (MSG_BROADCAST, self.origin_z);
  860.     }
  861.  
  862.     remove(self);
  863.  
  864. };
  865.  
  866. void() superspike_touch =
  867. {
  868. local float rand;
  869.     if (other == self.owner)
  870.         return;
  871.  
  872.     if (other.solid == SOLID_TRIGGER)
  873.         return;     // trigger field, do nothing
  874.  
  875.     if (pointcontents(self.origin) == CONTENT_SKY)
  876.     {
  877.         remove(self);
  878.         return;
  879.     }
  880.     
  881. // hit something that bleeds
  882.     if (other.takedamage)
  883.     {
  884.         spawn_touchblood (18);
  885.         T_Damage (other, self, self.owner, 18);
  886.     }
  887.     else
  888.     {
  889.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  890.         WriteByte (MSG_BROADCAST, TE_SUPERSPIKE);
  891.         WriteCoord (MSG_BROADCAST, self.origin_x);
  892.         WriteCoord (MSG_BROADCAST, self.origin_y);
  893.         WriteCoord (MSG_BROADCAST, self.origin_z);
  894.     }
  895.  
  896.     remove(self);
  897.  
  898. };
  899.  
  900.  
  901. /*
  902. ===============================================================================
  903.  
  904. PLAYER WEAPON USE
  905.  
  906. ===============================================================================
  907. */
  908.  
  909. void() W_SetCurrentAmmo =
  910. {
  911.     player_run ();          // get out of any weapon firing states
  912.  
  913.     self.items = self.items - ( self.items & (IT_SHELLS | IT_NAILS | IT_ROCKETS | IT_CELLS) );
  914.     
  915.     if (self.weapon == IT_AXE)
  916.     {
  917.         self.currentammo = 0;
  918.         self.weaponmodel = "progs/v_axe.mdl";
  919.         self.weaponframe = 0;
  920.     }
  921.     else if (self.weapon == IT_SHOTGUN)
  922.     {
  923.         self.currentammo = self.ammo_shells;
  924.         self.weaponmodel = "progs/v_shot.mdl";
  925.         self.weaponframe = 0;
  926.         self.items = self.items | IT_SHELLS;
  927.     }
  928.     else if (self.weapon == IT_SUPER_SHOTGUN)
  929.     {
  930.         self.currentammo = self.ammo_shells;
  931.         self.weaponmodel = "progs/v_shot2.mdl";
  932.         self.weaponframe = 0;
  933.         self.items = self.items | IT_SHELLS;
  934.     }
  935.     else if (self.weapon == IT_NAILGUN)
  936.     {
  937.         self.currentammo = self.ammo_nails;
  938.         self.weaponmodel = "progs/v_nail.mdl";
  939.         self.weaponframe = 0;
  940.         self.items = self.items | IT_NAILS;
  941.     }
  942.     else if (self.weapon == IT_SUPER_NAILGUN)
  943.     {
  944.         self.currentammo = self.ammo_nails;
  945.         self.weaponmodel = "progs/v_nail2.mdl";
  946.         self.weaponframe = 0;
  947.         self.items = self.items | IT_NAILS;
  948.     }
  949.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  950.     {
  951.         self.currentammo = self.ammo_rockets;
  952.         self.weaponmodel = "progs/v_rock.mdl";
  953.         self.weaponframe = 0;
  954.         self.items = self.items | IT_ROCKETS;
  955.     }
  956.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  957.     {
  958.         self.currentammo = self.ammo_rockets;
  959.         self.weaponmodel = "progs/v_rock2.mdl";
  960.         self.weaponframe = 0;
  961.         self.items = self.items | IT_ROCKETS;
  962.     }
  963.     else if (self.weapon == IT_LIGHTNING)
  964.     {
  965.         self.currentammo = self.ammo_cells;
  966.         self.weaponmodel = "progs/v_light.mdl";
  967.         self.weaponframe = 0;
  968.         self.items = self.items | IT_CELLS;
  969.     }
  970.     else
  971.     {
  972.         self.currentammo = 0;
  973.         self.weaponmodel = "";
  974.         self.weaponframe = 0;
  975.     }
  976. };
  977.  
  978. float() W_BestWeapon =
  979. {
  980.     local float it;
  981.     
  982.     it = self.items;
  983.  
  984.     if(self.ammo_cells >= 1 && (it & IT_LIGHTNING) )
  985.         return IT_LIGHTNING;
  986.     else if(self.ammo_nails >= 2 && (it & IT_SUPER_NAILGUN) )
  987.         return IT_SUPER_NAILGUN;
  988.     else if(self.ammo_shells >= 2 && (it & IT_SUPER_SHOTGUN) )
  989.         return IT_SUPER_SHOTGUN;
  990.     else if(self.ammo_nails >= 1 && (it & IT_NAILGUN) )
  991.         return IT_NAILGUN;
  992.     else if(self.ammo_shells >= 1 && (it & IT_SHOTGUN) )
  993.         return IT_SHOTGUN;
  994.         
  995. /*
  996.     if(self.ammo_rockets >= 1 && (it & IT_ROCKET_LAUNCHER) )
  997.         return IT_ROCKET_LAUNCHER;
  998.     else if(self.ammo_rockets >= 1 && (it & IT_GRENADE_LAUNCHER) )
  999.         return IT_GRENADE_LAUNCHER;
  1000.  
  1001. */
  1002.  
  1003.     return IT_AXE;
  1004. };
  1005.  
  1006. float() W_CheckNoAmmo =
  1007. {
  1008.     if (self.currentammo > 0)
  1009.         return TRUE;
  1010.  
  1011.     if (self.weapon == IT_AXE)
  1012.         return TRUE;
  1013.     
  1014.     self.weapon = W_BestWeapon ();
  1015.  
  1016.     W_SetCurrentAmmo ();
  1017.     
  1018. // drop the weapon down
  1019.     return FALSE;
  1020. };
  1021.  
  1022. /*
  1023. ============
  1024. W_Attack
  1025.  
  1026. An attack impulse can be triggered now
  1027. ============
  1028. */
  1029. void()      player_axe1;
  1030. void()      player_axeb1;
  1031. void()      player_axec1;
  1032. void()      player_axed1;
  1033. void()      player_shot1;
  1034. void()      player_nail1;
  1035. void()      player_light1;
  1036. void()      player_rocket1;
  1037.  
  1038. void() W_Attack =
  1039. {
  1040.     local float r;
  1041.  
  1042.     if (!W_CheckNoAmmo ())
  1043.         return;
  1044.  
  1045.     makevectors (self.v_angle);               // calculate forward angle for velocity
  1046.     self.show_hostile = time + 1; // wake monsters up
  1047.  
  1048.     if (self.weapon == IT_AXE)
  1049.     {
  1050.         sound (self, CHAN_WEAPON, "weapons/ax1.wav", 1, ATTN_NORM);
  1051.         r = random();
  1052.         if (r < 0.25)
  1053.             player_axe1 ();
  1054.         else if (r<0.5)
  1055.             player_axeb1 ();
  1056.         else if (r<0.75)
  1057.             player_axec1 ();
  1058.         else
  1059.             player_axed1 ();
  1060.         self.attack_finished = time + 0.5;
  1061.     }
  1062.     else if (self.weapon == IT_SHOTGUN)
  1063.     {
  1064.         player_shot1 ();
  1065.         W_FireShotgun ();
  1066.         self.attack_finished = time + 0.5;
  1067.     }
  1068.     else if (self.weapon == IT_SUPER_SHOTGUN)
  1069.     {
  1070.         player_shot1 ();
  1071.         W_FireSuperShotgun ();
  1072.         self.attack_finished = time + 0.7;
  1073.     }
  1074.     else if (self.weapon == IT_NAILGUN)
  1075.     {
  1076.         player_nail1 ();
  1077.     }
  1078.     else if (self.weapon == IT_SUPER_NAILGUN)
  1079.     {
  1080.         player_nail1 ();
  1081.     }
  1082.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  1083.     {
  1084.         player_rocket1();
  1085.         W_FireGrenade();
  1086.         self.attack_finished = time + 0.6;
  1087.     }
  1088.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  1089.     {
  1090.         player_rocket1();
  1091.         W_FireRocket();
  1092.         self.attack_finished = time + 0.8;
  1093.     }
  1094.     else if (self.weapon == IT_LIGHTNING)
  1095.     {
  1096.         player_light1();
  1097.         self.attack_finished = time + 0.1;
  1098.         sound (self, CHAN_AUTO, "weapons/lstart.wav", 1, ATTN_NORM);
  1099.     }
  1100. };
  1101.  
  1102. /*
  1103. ============
  1104. W_ChangeWeapon
  1105.  
  1106. ============
  1107. */
  1108. void() W_ChangeWeapon =
  1109. {
  1110.     local float it, am, fl;
  1111.     
  1112.     it = self.items;
  1113.     am = 0;
  1114.     
  1115.     if (self.impulse == 1)
  1116.     {
  1117.         fl = IT_AXE;
  1118.     }
  1119.     else if (self.impulse == 2)
  1120.     {
  1121.         fl = IT_SHOTGUN;
  1122.         if (self.ammo_shells < 1)
  1123.             am = 1;
  1124.     }
  1125.     else if (self.impulse == 3)
  1126.     {
  1127.         fl = IT_SUPER_SHOTGUN;
  1128.         if (self.ammo_shells < 2)
  1129.             am = 1;
  1130.     }           
  1131.     else if (self.impulse == 4)
  1132.     {
  1133.         fl = IT_NAILGUN;
  1134.         if (self.ammo_nails < 1)
  1135.             am = 1;
  1136.     }
  1137.     else if (self.impulse == 5)
  1138.     {
  1139.         fl = IT_SUPER_NAILGUN;
  1140.         if (self.ammo_nails < 2)
  1141.             am = 1;
  1142.     }
  1143.     else if (self.impulse == 6)
  1144.     {
  1145.         fl = IT_GRENADE_LAUNCHER;
  1146.         if (self.ammo_rockets < 1)
  1147.             am = 1;
  1148.     }
  1149.     else if (self.impulse == 7)
  1150.     {
  1151.         fl = IT_ROCKET_LAUNCHER;
  1152.         if (self.ammo_rockets < 1)
  1153.             am = 1;
  1154.     }
  1155.     else if (self.impulse == 8)
  1156.     {
  1157.         fl = IT_LIGHTNING;
  1158.         if (self.ammo_cells < 1)
  1159.             am = 1;
  1160.     }
  1161.  
  1162.     self.impulse = 0;
  1163.     
  1164.     if (!(self.items & fl))
  1165.     {     // don't have the weapon or the ammo
  1166.         sprint (self, "no weapon.\n");
  1167.         return;
  1168.     }
  1169.     
  1170.     if (am)
  1171.     {     // don't have the ammo
  1172.         sprint (self, "not enough ammo.\n");
  1173.         return;
  1174.     }
  1175.  
  1176. //
  1177. // set weapon, set ammo
  1178. //
  1179.     self.weapon = fl;       
  1180.     W_SetCurrentAmmo ();
  1181. };
  1182.  
  1183. /*
  1184. ============
  1185. CheatCommand
  1186. ============
  1187. */
  1188. void() CheatCommand =
  1189. {
  1190.     if (deathmatch || coop)
  1191.         return;
  1192.  
  1193.     self.ammo_rockets = 100;
  1194.     self.ammo_nails = 200;
  1195.     self.ammo_shells = 100;
  1196.     self.items = self.items | 
  1197.         IT_AXE |
  1198.         IT_SHOTGUN |
  1199.         IT_SUPER_SHOTGUN |
  1200.         IT_NAILGUN |
  1201.         IT_SUPER_NAILGUN |
  1202.         IT_GRENADE_LAUNCHER |
  1203.         IT_ROCKET_LAUNCHER |
  1204.         IT_KEY1 | IT_KEY2;
  1205.  
  1206.     self.ammo_cells = 200;
  1207.     self.items = self.items | IT_LIGHTNING;
  1208.  
  1209.     self.weapon = IT_ROCKET_LAUNCHER;
  1210.     self.impulse = 0;
  1211.     W_SetCurrentAmmo ();
  1212. };
  1213.  
  1214. /*
  1215. ============
  1216. CycleWeaponCommand
  1217.  
  1218. Go to the next weapon with ammo
  1219. ============
  1220. */
  1221. void() CycleWeaponCommand =
  1222. {
  1223.     local float it, am;
  1224.     
  1225.     it = self.items;
  1226.     self.impulse = 0;
  1227.     
  1228.     while (1)
  1229.     {
  1230.         am = 0;
  1231.  
  1232.         if (self.weapon == IT_LIGHTNING)
  1233.         {
  1234.             self.weapon = IT_AXE;
  1235.         }
  1236.         else if (self.weapon == IT_AXE)
  1237.         {
  1238.             self.weapon = IT_SHOTGUN;
  1239.             if (self.ammo_shells < 1)
  1240.                 am = 1;
  1241.         }
  1242.         else if (self.weapon == IT_SHOTGUN)
  1243.         {
  1244.             self.weapon = IT_SUPER_SHOTGUN;
  1245.             if (self.ammo_shells < 2)
  1246.                 am = 1;
  1247.         }           
  1248.         else if (self.weapon == IT_SUPER_SHOTGUN)
  1249.         {
  1250.             self.weapon = IT_NAILGUN;
  1251.             if (self.ammo_nails < 1)
  1252.                 am = 1;
  1253.         }
  1254.         else if (self.weapon == IT_NAILGUN)
  1255.         {
  1256.             self.weapon = IT_SUPER_NAILGUN;
  1257.             if (self.ammo_nails < 2)
  1258.                 am = 1;
  1259.         }
  1260.         else if (self.weapon == IT_SUPER_NAILGUN)
  1261.         {
  1262.             self.weapon = IT_GRENADE_LAUNCHER;
  1263.             if (self.ammo_rockets < 1)
  1264.                 am = 1;
  1265.         }
  1266.         else if (self.weapon == IT_GRENADE_LAUNCHER)
  1267.         {
  1268.             self.weapon = IT_ROCKET_LAUNCHER;
  1269.             if (self.ammo_rockets < 1)
  1270.                 am = 1;
  1271.         }
  1272.         else if (self.weapon == IT_ROCKET_LAUNCHER)
  1273.         {
  1274.             self.weapon = IT_LIGHTNING;
  1275.             if (self.ammo_cells < 1)
  1276.                 am = 1;
  1277.         }
  1278.     
  1279.         if ( (self.items & self.weapon) && am == 0)
  1280.         {
  1281.             W_SetCurrentAmmo ();
  1282.             return;
  1283.         }
  1284.     }
  1285.  
  1286. };
  1287.  
  1288. /*
  1289. ============
  1290. ServerflagsCommand
  1291.  
  1292. Just for development
  1293. ============
  1294. */
  1295. void() ServerflagsCommand =
  1296. {
  1297.     serverflags = serverflags * 2 + 1;
  1298. };
  1299.  
  1300. void() QuadCheat =
  1301. {
  1302.     if (deathmatch || coop)
  1303.         return;
  1304.     self.super_time = 1;
  1305.     self.super_damage_finished = time + 30;
  1306.     self.items = self.items | IT_QUAD;
  1307.     dprint ("quad cheat\n");
  1308. };
  1309.  
  1310. /*
  1311. ============
  1312. ImpulseCommands
  1313.  
  1314. ============
  1315. */
  1316. void() ImpulseCommands =
  1317. {
  1318.     if (self.impulse >= 1 && self.impulse <= 8)
  1319.         W_ChangeWeapon ();
  1320.  
  1321.     if (self.impulse == 9)
  1322.         CheatCommand ();
  1323.     if (self.impulse == 10)
  1324.         CycleWeaponCommand ();
  1325.     if (self.impulse == 11)
  1326.         ServerflagsCommand ();
  1327.     if (self.impulse == 12)
  1328.         if (self.Shocka_Gun_Active)
  1329.         {      
  1330.             self.Shocka_Gun_Active = FALSE;
  1331.             bprint("using normal ammo\n");
  1332.         }
  1333.         else
  1334.         {
  1335.             self.Shocka_Gun_Active = TRUE;
  1336.             bprint("using Shocka(TM) ammo\n");
  1337.         }
  1338.  
  1339.     if (self.impulse == 255)
  1340.         QuadCheat ();
  1341.         
  1342.     self.impulse = 0;
  1343. };
  1344.  
  1345. /*
  1346. ============
  1347. W_WeaponFrame
  1348.  
  1349. Called every frame so impulse events can be handled as well as possible
  1350. ============
  1351. */
  1352. void() W_WeaponFrame =
  1353. {
  1354.     if (time < self.attack_finished)
  1355.         return;
  1356.  
  1357.     ImpulseCommands ();
  1358.     
  1359. // check for attack
  1360.     if (self.button0)
  1361.     {
  1362.         SuperDamageSound ();
  1363.         W_Attack ();
  1364.     }
  1365. };
  1366.  
  1367. /*
  1368. ========
  1369. SuperDamageSound
  1370.  
  1371. Plays sound if needed
  1372. ========
  1373. */
  1374. void() SuperDamageSound =
  1375. {
  1376.     if (self.super_damage_finished > time)
  1377.     {
  1378.         if (self.super_sound < time)
  1379.         {
  1380.             self.super_sound = time + 1;
  1381.             sound (self, CHAN_BODY, "items/damage3.wav", 1, ATTN_NORM);
  1382.         }
  1383.     }
  1384.     return;
  1385. };
  1386.  
  1387.  
  1388.